//
//  ViewController.m
//  bum
//
//  Created by xingshuai on 2020/12/26.
//

#import "ViewController.h"

#import "BMViewController.h"
#import <Photos/Photos.h>
//#import <TZImagePickerController.h>
#import "BMListViewController.h"

@interface ViewController () ///<TZImagePickerControllerDelegate>

@property (nonatomic, strong) UIButton *btnImg;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"XS";
    self.view.backgroundColor = [UIColor orangeColor];
    
    self.btnImg = [UIButton buttonWithType:UIButtonTypeCustom];
    self.btnImg.frame = CGRectMake(0, 0, self.view.frame.size.width-150, self.view.frame.size.width-150);
    self.btnImg.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/3);
    self.btnImg.backgroundColor = [UIColor whiteColor];
    [self.btnImg addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.btnImg];
    
}

-(void)clickBtn {
    __weak typeof(self) weakSelf = self;
    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
        if (status != PHAuthorizationStatusDenied) {
            dispatch_async(dispatch_get_main_queue(), ^{
                BMListViewController *vc = [[BMListViewController alloc]init];
                [weakSelf.navigationController pushViewController:vc animated:YES];
            });
        } else {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSString *mesStr = [NSString stringWithFormat:@"您未允许访问您的照片，请在‘设置-隐私-照片’中更改设置"];
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"未能获取到照片权限" message:mesStr preferredStyle:UIAlertControllerStyleAlert];
                [alert addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:nil]];
                [weakSelf presentViewController:alert animated:YES completion:nil];
            });
        }
    }];
    
}


@end
